package com.chb.myWeather;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * 自定义分组， 
 * 默认的分组是按照key是否相同，
 */
public class MyGroup extends WritableComparator{
	public MyGroup() {
		super(MyKey.class, true);
	}
	
	/**
	 * 由于分组是按照月份分组，所以在比较是只要比较月份是否相同，
	 * 其他略去，做数据过滤
	 */
	public int compare(WritableComparable a, WritableComparable b) {
		MyKey k1 = (MyKey)a;
		MyKey k2 = (MyKey)b;
		int r1 = Integer.compare(k1.getYear(), k2.getYear());
		if (r1 == 0) {
			return Integer.compare(k1.getMonth(), k2.getMonth());
		}else {
			return r1;
		}	
	}

}
